{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑课程</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="userEdit" id="userEdit" method="post" action="{:url('nianji_course_edit')}">

                        <div class="form-group" >
                            <table class="table table-bordered table-hover" id="table">
                                <thead>
                                <tr class="long-tr">
                                    <th>科目</th>
                                    <th>学时</th>
                                    <th>操作</th>
                                </tr>
                                </thead>

                                {if(!empty($info))}
                                {foreach name='info' item='vv'}
                                    <tr id="ccc_{$vv.id}">
                                        <td>
                                            <select class="form-control" name="name[]">
                                                {foreach name='course' item='vo'}
                                                     <option value='{$vo.name}' {if condition="$vo['name'] eq $vv.name"} selected {/if}>{$vo.name}</option>
                                                {/foreach}
                                            </select>
                                        </td>
                                        <td><input type="text" name="num[]" class="form-control" value="{$vv.num}" ></td>
                                        <td style="text-align: center;"><a href="javascript:;" onclick="delinput({$vv.id})" class="btn btn-danger btn-xs">
                                            <i class="fa fa-trash-o"></i> 删除</a></td>
                                    </tr>
                                {/foreach}
                                {else}
                                    <!--<tr id="ccc_1">-->
                                        <!--<td>-->
                                            <!--<select class="form-control" name="name[]">-->
                                                <!--{foreach name='course' item='vo'}-->
                                                <!--<option value='{$vo.name}'>{$vo.name}</option>-->
                                                <!--{/foreach}-->
                                            <!--</select>-->
                                        <!--</td>-->
                                        <!--<td><input type="text" name="num[]" class="form-control"  ></td>-->
                                        <!--<td style="text-align: center;"><a href="javascript:;" onclick="delinput(1)" class="btn btn-danger btn-xs">-->
                                            <!--<i class="fa fa-trash-o"></i> 删除</a></td>-->
                                    <!--</tr>-->

                                {/if}





                             </table>
                            <p style="text-align: center;">
                                <a href="javascript:;" class="btn btn-primary" onclick="addinput();"> 新增课程 </a>
                            </p>







                        </div>



                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <input type="hidden" name="nianji" value="{$id}" >
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<script type="text/javascript">
    //提交
    $(function(){
        $('#userEdit').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
            $("input:text").each(function() {
                if($.trim($(this).val()) == "") {
                    layer.msg('学时不能为空', {icon: 5,time:1500,shade: 0.1});
                    return false;
                }
            });
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('course/nianji_course')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }
        }

    });

    function addinput(){

        var t='';
        for(var i=0;i<5;i++){
            t+=Math.floor(Math.random()*10);
        }
        t = "1"+t;
        var q = "ccc_"+t;
        var $htmlLi = $("<tr id='"+q+"'><td><select class='form-control' name='name[]'>{foreach name='course' item='vo'}<option value='{$vo.name}'>{$vo.name}</option>{/foreach}</select></td><td><input type='text'name='num[]'class='form-control'></td><td style='text-align: center;'><a href='javascript:;' onclick='delinput("+t+")' class='btn btn-danger btn-xs'><i class='fa fa-trash-o'></i> 删除</a></td></tr>");  //创建DOM对象
        var $ul = $('#table');
        $ul.append($htmlLi);
    }

    function delinput(i){
        var q = "#ccc_"+i;
        $(q).remove();
    }



    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>